#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

map<string,string> ma = {{"Jan", "01"}, {"Feb", "02"}, {"Mar", "03"}, {"Apr", "04"}, {"May", "05"}, {"Jun", "06"}, {"Jul", "07"}, {"Aug", "08"}, {"Sep", "09"}, {"Oct", "10"}, {"Nov", "11"}, {"Dec","12"}};

signed main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string m,y,d;
        int d1,y1;
        cin>>m;
        scanf(" %d, %d",&d1,&y1);
        m = ma[m];
        y=to_string(y1);
        d=to_string(d1);
        while(y.size()<4)    y = "0"+y;
        while(d.size()<2)    d = "0"+d;
        string rev = y+m+d;
        reverse(rev.begin(),rev.end());
        if(rev==y+m+d)    cout<<"Y ";
        else    cout<<"N ";
        cout<<y+m+d<<"\n";
    }
    return 0;
}
